﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.InventoryUI {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.MarketUI.*;
    import Display.aswingui.*;
    import Engine.*;

    public class InventoryView extends Catalog {

        public static const SCROLL_HEIGHT:int = 550;

        public static var assetDict:Dictionary;

        protected var m_forceStayOpen:Boolean = false;
        protected var m_refreshEntireInventory:Boolean = false;

        public function InventoryView(_arg1:String=null){
            var _local2:InventoryCatalogUI = new InventoryCatalogUI();
            super("", _local2, _arg1, false, "", false);
        }
        public static function setupAssets(_arg1:DisplayObject, _arg2:String):void{
            var _local3:InventoryView = new (InventoryView)();
            _local3.makeAssets(_arg1, _arg2);
        }

        public function get forceStayOpen():Boolean{
            return (this.m_forceStayOpen);
        }
        public function get doRefreshInventory():Boolean{
            return (this.m_refreshEntireInventory);
        }
        override protected function loadAssets():void{
            m_content = m_ui;
            Global.delayedAssets.get(DelayedAssetLoader.INVENTORY_ASSETS, this.makeAssets);
            var _local1:Sprite = new Sprite();
            this.addChild(_local1);
            var _local2:JWindow = new JWindow(_local1);
            _local2.setContentPane(m_ui);
            ASwingHelper.prepare(_local2);
            _local2.show();
        }
        override protected function makeAssets(_arg1:DisplayObject, _arg2:String):void{
            m_comObject = _arg1;
            this.setChrome(null);
        }
        override public function centerPopup():void{
            var _local1:Rectangle;
            var _local2:Point;
            var _local3:Number;
            this.m_forceStayOpen = false;
            if (parent){
                _local1 = Global.hud.getRect(parent);
                _local2 = new Point(((Global.stage.stageWidth - m_content.width) / 2), Global.stage.stageHeight);
                _local3 = Global.hud.localToGlobal(new Point(Global.hud.x, Global.hud.y)).x;
                this.x = (_local2.x - _local3);
                this.y = (_local1.y + _local2.y);
            };
        }
        override protected function onFullScreen(_arg1:FullScreenEvent):void{
            var _local2:Rectangle;
            var _local3:Point;
            var _local4:Number;
            if (parent){
                _local2 = Global.hud.getRect(parent);
                _local3 = new Point(((Global.stage.stageWidth - m_content.width) / 2), ((Global.stage.stageHeight + CATALOG_TWEEN_OFFSET) - this.getScrollHeight()));
                _local4 = Global.hud.localToGlobal(new Point(Global.hud.x, Global.hud.y)).x;
                this.x = (_local3.x - _local4);
                this.y = (_local2.y + _local3.y);
            };
        }
        override protected function setChrome(_arg1:Event):void{
            InventoryView.assetDict = new Dictionary(true);
            InventoryView.assetDict["btn_prev_up"] = m_comObject.btn_prev_up;
            InventoryView.assetDict["btn_prev_over"] = m_comObject.btn_prev_over;
            InventoryView.assetDict["btn_prev_down"] = m_comObject.btn_prev_down;
            InventoryView.assetDict["btn_next_up"] = m_comObject.btn_next_up;
            InventoryView.assetDict["btn_next_over"] = m_comObject.btn_next_over;
            InventoryView.assetDict["btn_next_down"] = m_comObject.btn_next_down;
            InventoryView.assetDict["btn_close_big_up"] = m_comObject.btn_close_big_up;
            InventoryView.assetDict["btn_close_big_over"] = m_comObject.btn_close_big_over;
            InventoryView.assetDict["btn_close_big_down"] = m_comObject.btn_close_big_down;
            InventoryView.assetDict["btn_close_small_up"] = m_comObject.btn_close_small_up;
            InventoryView.assetDict["btn_close_small_over"] = m_comObject.btn_close_small_over;
            InventoryView.assetDict["btn_close_small_down"] = m_comObject.btn_close_small_down;
            InventoryView.assetDict["verticalRule"] = m_comObject.verticalRule;
            InventoryView.assetDict["collectionFlyout"] = m_comObject.collectionFlyout;
            InventoryView.assetDict["collections_inventory_item"] = m_comObject.inventoryCollectionsItem;
            InventoryView.assetDict["collections_item_empty"] = m_comObject.collectionsItemEmpty;
            InventoryView.assetDict["wishlistItem"] = m_comObject.wishlistItem;
            InventoryView.assetDict["countBG"] = m_comObject.countBG;
            InventoryView.assetDict["countMaxBG"] = m_comObject.countMaxBG;
            InventoryView.assetDict["gift_down"] = m_comObject.btn_gift_down;
            InventoryView.assetDict["gift_over"] = m_comObject.btn_gift_over;
            InventoryView.assetDict["gift_up"] = m_comObject.btn_gift_up;
            InventoryView.assetDict["wishlist_icon"] = m_comObject.wishlistIcon;
            InventoryView.assetDict["inventory_card"] = m_comObject.inventoryCard;
            InventoryView.assetDict["add_to_wishlist"] = m_comObject.addtoWishList;
            InventoryView.assetDict["inventory_card_locked"] = m_comObject.inventoryCardLocked;
            InventoryView.assetDict["collectionsCard_ready"] = m_comObject.collectionsCardReady;
            var _local2 = "";
            asset.init(m_type, this, _local2, false, "");
            m_cursorId = UI.setCursor(null);
            this.mouseEnabled = (this.mouseChildren = true);
            if (m_itemName != null){
                asset.goToItem(m_itemName);
            };
        }
        override public function canBuy(_arg1:Item):Boolean{
            return (true);
        }
        override public function close():void{
            super.close();
        }
        public function allowClose():void{
            this.m_forceStayOpen = false;
        }
        override public function onBuy(_arg1:Item, _arg2:Object=null):void{
            var _local5:Array;
            var _local6:int;
            var _local7:Item;
            this.m_forceStayOpen = false;
            if (!_arg1){
                return;
            };
            var _local3:int = MarketEvent.GENERIC;
            var _local4:Boolean;
            switch (_arg1.type){
                case "tool":
                    _local3 = MarketEvent.EQUIPMENT;
                    break;
                case "contract":
                    _local3 = MarketEvent.CONTRACT;
                    break;
                case "residence":
                    _local3 = MarketEvent.RESIDENCE;
                    break;
                case "business":
                    _local3 = MarketEvent.BUSINESS;
                    break;
                case "plot_contract":
                    _local3 = MarketEvent.CONTRACT;
                    break;
                case "ship_contract":
                    _local3 = MarketEvent.CONTRACT;
                    break;
                case "expansion":
                    _local3 = MarketEvent.EXPAND_FARM;
                    break;
                case "bridge":
                    dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.BRIDGE, _arg1.name, false, false, MarketEvent.SOURCE_INVENTORY));
                    break;
                case "energy":
                    _local5 = Global.player.inventory.getItems();
                    _local6 = 0;
                    for each (_local7 in _local5) {
                        if (((((_local7) && ((_local7.energyRewards > 0)))) && ((Global.player.inventory.getItemCount(_local7) > 0)))){
                            _local6 = (_local6 + Global.player.inventory.getItemCount(_local7));
                        };
                    };
                    if (_local6 <= 1){
                        this.m_refreshEntireInventory = true;
                    };
                    this.m_forceStayOpen = true;
                    if (Global.player.inventory.getItemCount(_arg1) > 0){
                        _local3 = MarketEvent.EXTRA;
                    } else {
                        _local4 = false;
                    };
                    break;
                case "theme_collection":
                    _local3 = MarketEvent.THEME_COLLECTION;
                    break;
                case "goods":
                    _local3 = MarketEvent.GOODS;
                    break;
            };
            if (_local4){
                dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, _local3, _arg1.name, false, false, MarketEvent.SOURCE_INVENTORY));
            };
            if (!this.m_forceStayOpen){
                if ((((m_closeMarket == true)) || (UI.AUTO_CLOSE_MARKET))){
                    onCloseClick(true);
                };
            };
        }
        override public function getExpandedMainMenuPosition():Vector2{
            return (new Vector2(665, 120));
        }
        override protected function getScrollHeight():int{
            if (Utilities.isFullScreen()){
                return (((Global.stage.stageHeight / 2) + (m_ui.height / 2)));
            };
            return (SCROLL_HEIGHT);
        }
        override public function show():void{
            super.show();
            this.refreshInventory();
        }
        public function refreshInventory():void{
            this.asset.refreshShelf();
        }
        public function refreshInventoryLimit():void{
            (this.asset as InventoryCatalogUI).refreshInventoryLimit();
        }

    }
}//package Display.InventoryUI 
